package com.hjq.controller;

import com.hjq.common.PageResult;
import com.hjq.common.Result;
import com.hjq.entity.po.Topic;
import com.hjq.service.TopicService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 专题管理
 **/
@Slf4j
@RestController
@RequestMapping("/topic")
public class TopicController {
    @Autowired
    private TopicService topicService;

    /**
     * 专题列表
     *
     */
    @GetMapping
    public Result<PageResult<Topic>> list() {
        PageResult<Topic> result  = topicService.findAll();
        log.info("专题分页查询,{}",result);
        return Result.success(result);
    }
    /**
     * 添加专题
     */
    @PostMapping
    public Result<Object> add(@RequestBody Topic topic){
        topicService.add(topic);
        return Result.success("添加成功");
    }
    /**
     * 删除专题
     */
    @DeleteMapping("/{id}")
    public Result<Object> delete(@PathVariable Integer id) {
        topicService.deleteById(id);
        return Result.success("删除成功");
    }
    /**
     * 修改专题
     */
    @PutMapping
    public Result<Object> update(@RequestBody Topic topic) {
        topicService.update(topic);
        return Result.success("修改成功");
    }
}
